/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.startup.musicstore.services.Impl;

import com.startup.musicstore.model.Customer;
import com.startup.musicstore.model.CustomerAddress;
import com.startup.musicstore.services.CustomerDetails;
import com.startup.musicstore.services.crud.CustomerCrudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author linda
 */
@Service("customerDetailsService")
@Transactional
public class CustomerDetailsImpl implements CustomerDetails{
    
    @Autowired
    private CustomerCrudService customerCrudService;

    @Override
    public CustomerAddress getCustomerAdress(String custNo) {
        //get a customer first
      //Customer Actualcust = (Customer) customerCrudService.findById(cust.getId());
      //if was to get by customer number will pass a string number then the above code will be
      Customer Actualcust = (Customer) customerCrudService.getByPropertyName("customerNumber", custNo);
      //will get the customer with that particular number
      return Actualcust.getCustomeraddress();
    }

    @Override
    public String getCellNumber(Customer cust) {
        
        Customer Actualcust = (Customer) customerCrudService.findById(cust.getId());
        return Actualcust.getContact().getCellNumber();
    }
    
    
    
}
